package com.hejia.alauda.persistence.mybatis;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hejia.alauda.entity.SystemMessage;
import com.hejia.alauda.persistence.BaseMapper;

public interface SystemMessageMapper extends BaseMapper<SystemMessage> {

	/**
	 * 获取接收人未获取的系统消息
	 * 
	 * @param receiverId
	 */
	@Select("select a.* from systemMessage a where a.deadFlag=false and a.publishFlag=true and a.deadline>now() and a.id not in(select message_id from message b where b.receiver_id=#{receiverId} and b.type='S')")
	@ResultMap("ListMap")
	public List<SystemMessage> getSystemMessageByReceiver(
			@Param("receiverId") Long receiverId);

	@Update("update systemMessage set deadFlag=true where deadline<now()")
	public void setSystemMessageDead();
}
